
import com.jme3.input.controls.KeyTrigger;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
import de.stoneageracer.core.RacingApplication;
import de.stoneageracer.core.SettingsManager;
import de.stoneageracer.vehicles.Car;
import de.stoneageracer.vehicles.VehiclePart;
import java.io.IOException;

/**
 *
 * @author Basti
 */
public class MenuTest extends RacingApplication{
        
    /**
     * Overrides simpleInit Method of RacingApplication
     * Put all your Menu-Initialising Code here!
     */
    @Override
    public void simpleInitApp(){
        super.simpleInitApp();
        initPhysics();        
        Node world = initWorld("Scenes/Strecke1/Street_Test.scene", "Scenes/Strecke1/Street_C.mesh.xml",1,new Vector3f(0,-14,0));
        Geometry land = findGeom(world, "Landscape");
        //land.getMaterial().setTexture("NormalMap", assetManager.loadTexture("Scenes/Strecke1/street_1_NRM.jpg"));
        //land.getMaterial().setTexture("SpecularMap", assetManager.loadTexture("Scenes/Strecke1/street_1_SPEC.jpg"));
        land = findGeom(world, "Street");
        //land.getMaterial().setTexture("NormalMap", assetManager.loadTexture("Scenes/Strecke1/street_1_NRM.jpg"));
        //land.getMaterial().setTexture("SpecularMap", assetManager.loadTexture("Scenes/Strecke1/street_1_SPEC.jpg"));
        initSky("Textures/himmel.jpg");
        initPostProcessing();
        Car car = new Car(this,"Models/Brumbrum/Car.scene");
        buildPlayer(car,10,-10,0).setPhysicsRotation(new Quaternion(0, FastMath.PI, 0, 0));
        flyCam.setEnabled(false);
        cam.setLocation(new Vector3f(16.650297f, -11.565172f, 5.7418084f));
        //cam.setDirection(new Vector3f(-0.83574337f, -0.18665203f, -0.5164244f));
        cam.lookAt(new Vector3f(-30,-10,-70), Vector3f.UNIT_Y);
        addGuiText("SinglePlayer\nMultiPlayer\nOptions\nEnd", new Vector3f(10, 100, 0)).setColor(new ColorRGBA(1,1,1,1));
        
        inputManager.addMapping("SinglePlayer", new KeyTrigger(keyInput.KEY_SPACE));
        inputManager.addListener(this, "SinglePlayer");
    }
    
    /**
     * Main method to start the Game
     * @param args
     */
    public static void main(String[] args) throws IOException{
        MenuTest mt = new MenuTest();
        mt.setShowSettings(false);
        mt.settings=SettingsManager.getSettings();
        mt.start();
    }

    /**
     * Key-Checks here (for now only loads a map when you press "SPACE"
     * @param name name of the Action
     * @param isPressed boolean whether a key is pressed
     * @param tpf "Time Per Frame"
     */
    @Override
    public void onAction(String name, boolean isPressed, float tpf) {
        super.onAction(name, isPressed, tpf);
        if(name.equals("SinglePlayer")&&isPressed){
            inputManager.removeListener(this);
            reset();
            simpleInitGame();
        }
        if(name.equals("Menu")&&isPressed){
            inputManager.removeListener(this);
            reset();
            simpleInitApp();
        }
        if(name.equals("Bloom")&&isPressed){
            if(SettingsManager.getValueOfSetting("gfx_bloom") == 1){
                SettingsManager.setSettingValue("gfx_bloom", 0);
            }
            else SettingsManager.setSettingValue("gfx_bloom", 1);
            initPostProcessing();
        }
        if(name.equals("BAM")&&isPressed){
            car.detachPart(vp);
        }
    }
    private Car car;
    private VehiclePart vp;
    /**
     * Initialises a "Level"
     * Copy and rewrite this method for each level (dont forget to reset(); before you call this method
     */
    public void simpleInitGame(){
        System.out.println("Started GameTest");
        initPhysics();
        Node world = initWorld("Scenes/Strecke1/Street_Test.scene", "Scenes/Strecke1/Street_C.mesh.xml",3);
        Geometry land = findGeom(world, "Landscape");
        //land.getMaterial().setTexture("NormalMap", assetManager.loadTexture("Scenes/Strecke1/street_1_NRM.jpg"));
        //land.getMaterial().setTexture("SpecularMap", assetManager.loadTexture("Scenes/Strecke1/street_1_SPEC.jpg"));
        land = findGeom(world, "Street");
        //land.getMaterial().setTexture("NormalMap", assetManager.loadTexture("Scenes/Strecke1/street_1_NRM.jpg"));
        initSky("Textures/himmel.jpg");
        car = new Car(this,"Models/Ferrari/Car.scene");
        //car = new Car(this,"Models/Brumbrum/Car.scene");
        car.addTo(rootNode,-15,10,0);
        Spatial modl = assetManager.loadModel("Models/Ferrari/Car.scene");
        modl.scale(.4f);
        vp = new VehiclePart("Ferrari",modl, 1000);
        car.addPart(vp, new Vector3f(-1,1,1), new Quaternion(0, 0, .4f, 1));
        car.addPart(new VehiclePart("Ferrari",modl, 1000), new Vector3f(1,1,1), new Quaternion(0, 0, -.4f, 1));
        //carN.attachChild(createEmitter(new Vector3f(0,0,3),new ColorRGBA(0f, 0f, 0f, 1f),new ColorRGBA(1f, 1f, 1f, .4f)));//ParticleTest
        //buildPlayer(car,0,0,10);//SecondCar (Physics-)Test
        //flyCam.setEnabled(true);
        //flyCam.setMoveSpeed(40);
        initCam(car.node);
        initKeys();
        initPostProcessing();
        initKMH("Speed: ","kmh",new Vector3f(300, 40, 0));
        
        inputManager.addMapping("Menu", new KeyTrigger(keyInput.KEY_M));
        inputManager.addListener(this, "Menu");
        inputManager.addMapping("Bloom", new KeyTrigger(keyInput.KEY_B));
        inputManager.addListener(this, "Bloom");
        inputManager.addMapping("BAM",new KeyTrigger(keyInput.KEY_P));
        inputManager.addListener(this,"BAM");
    }
}
